<template>
  <div>
    <div class="menu-content">
      <el-menu
        :default-active="activeIndex"
        background-color="#eaeeef"
        text-color="#707171"
        active-text-color="#3d3d3d"
        mode="horizontal"
        @select="handleSelect"
      >
        <template v-for="item in menuList">
          <el-menu-item :index="item.path" :key="item.path">
            <div class="menu-style">
              <img :src="activeIndex === item.path ? item.urlActive : item.url" alt />
              {{ item.name }}
            </div>
          </el-menu-item>
        </template>
      </el-menu>
    </div>
    <keep-alive include="fwbp">
      <router-view />
    </keep-alive>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeIndex: '/nlgl/wdfb',
      menuList: [
        {
          name: '服务编排',
          path: '/nlgl/fwlcbp',
          url: require('@/assets/img/grzx/服务编排-默认.png'),
          urlActive: require('@/assets/img/grzx/服务编排-选中.png'),
        },
      ]
    }
  },
  methods: {
    // 路由跳转
    handleSelect(path) {
      this.$router.push(path);
    },
  },
  watch: {
    '$route.path': {
      handler(path) {
        // 如果菜单中包含该路由，则激活当前菜单
        const flag = this.menuList.some((item) => item.path === path);
        if (flag) {
          this.activeIndex = path;
        } else {
          this.activeIndex = this.menuList[0]?.path;
        }
      },
      immediate: true,
    },
    $route: {
      handler(to, from) {
        if (to.path === "/nlgl/wdfb") {
          this.menuList = [
            {
              name: '服务编排',
              path: '/nlgl/fwlcbp',
              url: require('@/assets/img/grzx/服务编排-默认.png'),
              urlActive: require('@/assets/img/grzx/服务编排-选中.png'),
            },
            {
              name: '认证鉴权',
              path: '/nlgl/aqrz',
              url: require('@/assets/img/grzx/认证鉴权-默认.png'),
              urlActive: require('@/assets/img/grzx/认证鉴权-选中.png'),
            },
          ];
          if (this.$store.state.personInfo.rybm.indexOf("A000") >= 0) {
            this.menuList.push({
              name: '能力分类',
              path: '/nlgl/adminMainpage',
              url: require('@/assets/img/grzx/能力分类-默认.png'),
              urlActive: require('@/assets/img/grzx/能力分类-选中.png'),
            })
            this.menuList.unshift({
              name: '我的发布',
              path: '/nlgl/wdfb',
              url: require('@/assets/img/grzx/我的发布-默认.png'),
              urlActive: require('@/assets/img/grzx/我的发布-选中.png'),
            })
          }
          this.activeIndex = "/nlgl/wdfb";
          return;
        }

        if (to.path === "/nlgl/fwlcbp") {
          this.menuList = [
            {
              name: '服务编排',
              path: '/nlgl/fwlcbp',
              url: require('@/assets/img/grzx/服务编排-默认.png'),
              urlActive: require('@/assets/img/grzx/服务编排-选中.png'),
            },
            {
              name: '认证鉴权',
              path: '/nlgl/aqrz',
              url: require('@/assets/img/grzx/认证鉴权-默认.png'),
              urlActive: require('@/assets/img/grzx/认证鉴权-选中.png'),
            },
          ];
          if (this.$store.state.personInfo.rybm.indexOf("A000") >= 0) {
            this.menuList.push({
              name: '能力分类',
              path: '/nlgl/adminMainpage',
              url: require('@/assets/img/grzx/能力分类-默认.png'),
              urlActive: require('@/assets/img/grzx/能力分类-选中.png'),
            })
            this.menuList.unshift({
              name: '我的发布',
              path: '/nlgl/wdfb',
              url: require('@/assets/img/grzx/我的发布-默认.png'),
              urlActive: require('@/assets/img/grzx/我的发布-选中.png'),
            })
          }
          this.activeIndex = "/nlgl/fwlcbp";
          return;
        }

        if (to.path === "/nlgl/adminMainpage") {
          this.menuList = [
            {
              name: '服务编排',
              path: '/nlgl/fwlcbp',
              url: require('@/assets/img/grzx/服务编排-默认.png'),
              urlActive: require('@/assets/img/grzx/服务编排-选中.png'),
            },
            {
              name: '认证鉴权',
              path: '/nlgl/aqrz',
              url: require('@/assets/img/grzx/认证鉴权-默认.png'),
              urlActive: require('@/assets/img/grzx/认证鉴权-选中.png'),
            },
            {
              name: '能力分类',
              path: '/nlgl/adminMainpage',
              url: require('@/assets/img/grzx/能力分类-默认.png'),
              urlActive: require('@/assets/img/grzx/能力分类-选中.png'),
            }
          ];
          if (this.$store.state.personInfo.rybm.indexOf('A000') >= 0) {
            this.menuList.unshift({
              name: '我的发布',
              path: '/nlgl/wdfb',
              url: require('@/assets/img/grzx/我的发布-默认.png'),
              urlActive: require('@/assets/img/grzx/我的发布-选中.png'),
            })
          }
          this.activeIndex = '/nlgl/adminMainpage';
          return
        }

        if (to.path === "/nlgl/aqrz") {
          this.menuList = [
            {
              name: '服务编排',
              path: '/nlgl/fwlcbp',
              url: require('@/assets/img/grzx/服务编排-默认.png'),
              urlActive: require('@/assets/img/grzx/服务编排-选中.png'),
            },
            {
              name: '认证鉴权',
              path: '/nlgl/aqrz',
              url: require('@/assets/img/grzx/认证鉴权-默认.png'),
              urlActive: require('@/assets/img/grzx/认证鉴权-选中.png'),
            },
          ];
          if (this.$store.state.personInfo.rybm.indexOf("A000") >= 0) {
            this.menuList.push({
              name: '能力分类',
              path: '/nlgl/adminMainpage',
              url: require('@/assets/img/grzx/能力分类-默认.png'),
              urlActive: require('@/assets/img/grzx/能力分类-选中.png'),
            })
            this.menuList.unshift({
              name: '我的发布',
              path: '/nlgl/wdfb',
              url: require('@/assets/img/grzx/我的发布-默认.png'),
              urlActive: require('@/assets/img/grzx/我的发布-选中.png'),
            })
          }
          this.activeIndex = "/nlgl/aqrz";
          return;
        }
      },
      immediate: true,
    },
  },
}

</script>

<style lang="scss" scoped>
.main-container {
  width: 100%;
  // height: 100%;
  overflow: auto;
  background: #fff;
  // 抬头
  .banner {
    width: 100%;
    height: 350px;
    // background: url("~@/assets/img/header/banner.png");
    padding: 200px 0 0 400px;
    span {
      display: inline-block;
      background: linear-gradient(to bottom, #ffff, #ffff, #e3eeff, #6fb0ff);
      -webkit-background-clip: text;
      color: transparent;
      font-size: 42px;
      -webkit-box-reflect: below 2px
        linear-gradient(transparent, rgba(0, 0, 0, 0.5));
    }
  }
  // 面包屑
  .bread-crumb {
    width: 1540px;
    margin: 0 auto;
    height: 60px;
    background: #fff;
    padding: 100px 0 0 0px;
  }

  // 路由
  .main-content {
    width: 100%;
    min-height: calc(100% - 490px);
    float: left;
    background-color: #eaeeef;
    display: flex;
    justify-content: center;
    .container {
      width: 1540px;
      margin: 25px 0;
    }
  }
  // 信息
  .bottom {
    width: 100%;
    height: 80px;
    background-color: #d6dbdc;
    text-align: center;
    line-height: 80px;
    color: #666666;
    float: left;
  }
}

.menu-content {
  margin-top: 10px;

  ::v-deep .el-menu.el-menu--horizontal {
    border-bottom: solid 1px #cecece;
  }

  ::v-deep .el-menu--horizontal > .el-menu-item.is-active {
    border-bottom: 3px solid #115fd4 !important;
  }
  .menu-style {
    font-size: 20px;
  }
}
</style>